local skill = fk.CreateSkill {
  name = "ling__jade_skill",
}

skill:addEffect("cardskill", {
  can_use = Util.FalseFunc,
})

skill:addEffect(fk.AfterCardsMove, {
  global = true,
  priority = 0.001,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not table.contains(player.room.disabled_packs, "ling_cards") then
      for _, move in ipairs(data) do
        if move.from == player and move.to ~= player and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from == player and move.to ~= player and move.toArea == Card.PlayerHand then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId, false).name == "ling__jade" then
            if not player.dead then
              player:drawCards(2, skill.name)
            end
            if move.to and not move.to.dead and table.contains(move.to:getCardIds("h"), info.cardId) then
              player.room:recastCard({info.cardId}, move.to, skill.name)
            end
          end
        end
      end
    end
  end,
})

skill:addEffect("maxcards", {
  global = true,
  exclude_from = function(self, player, card)
    return card and card.name == "ling__jade"
  end,
})

return skill
